﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Baik;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Baik.Interface.Execution;
using Baik.Interface.Expression;

namespace Tester
{
    [TestClass]
    public class BasicParsingTests
    {   //using Engine = Baik.Baik;
        public BaikInstance Instance = new BaikInstance();
        [TestMethod]
        public void Given_SingleQuotedString_When_Parse_Should_Return_StringLiteralExpression()
        {
            var exp = Instance.Parse("'text';");
            Assert.IsTrue(exp is IStringLiteral);
        
        }
        [TestMethod]
        public void Given_DoubleQuotedString_When_Parse_Should_Return_StringLiteralExpression()
        {
            var exp = Instance.Parse("\"text\";");
            Assert.IsTrue(exp is IStringLiteral);
        
        }
        [TestMethod]
        public void Given_Integer_When_Parse_Should_Return_NumberLiteralExpression()
        {
            var exp = Instance.Parse("9;");
            Assert.IsTrue(exp is INumberLiteral);
            Assert.IsTrue((exp as INumberLiteral).Value.Equals(9));
        }
        [TestMethod]
        public void Given_Float_When_Parse_Should_Return_NumberLiteralExpression()
        {
            var exp = Instance.Parse("9.9;");
            Assert.IsTrue(exp is INumberLiteral);
            Assert.IsTrue((exp as INumberLiteral).Value.Equals(9.9));
        }
        [TestMethod]
        public void Given_EmptyObjectLiteral_When_Parse_Should_Return_Empty_ObjectLiteralExpression()
        {
            var exp = Instance.Parse("{};");
            Assert.IsTrue(exp is IObjectLiteral);
            Assert.IsTrue(!(exp as IObjectLiteral).Assigments.Any());
        }
        [TestMethod]
        public void Given_EmptyArrayLiteral_When_Parse_Should_Return_Empty_ArrayLiteralExpression()
        {
            var exp = Instance.Parse("[];");
            Assert.IsTrue(exp is IArrayLiteral);
            Assert.IsTrue(!(exp as IArrayLiteral).Expressions.Any());
        }
        [TestMethod]
        public void Given_EmptyFunctionLiteral_When_Parse_Should_Return_Empty_FunctionLiteralExpression()
        {
            var exp = Instance.Parse("(){};");
            Assert.IsTrue(exp is IFunctionLiteral);
            Assert.IsTrue(!(exp as IFunctionLiteral).Expressions.Any());
        }
        [TestMethod]
        public void Given_FalseLiteral_When_Parse_Should_Return_FalseExpression()
        {
            var exp = Instance.Parse("false;");
            Assert.IsTrue(exp is Baik.Interface.Expression.IFalse);
            
        }
        [TestMethod]
        public void Given_TrueLiteral_When_Parse_Should_Return_TrueExpression()
        {
            var exp = Instance.Parse("true;");
            Assert.IsTrue(exp is Baik.Interface.Expression.ITrue);
        }
        [TestMethod]
        public void Given_UndefinedLiteral_When_Parse_Should_Return_UndefinedExpression()
        {
            var exp = Instance.Parse("undefined;");
            Assert.IsTrue(exp is Baik.Interface.Expression.IUndefined);
        }
        [TestMethod]
        public void Given_Valid_Assignment_When_Parse_Should_Return_AssignmentExpression()
        {
            var exp = Instance.Parse("a:undefined;");
            Assert.IsTrue(exp is Baik.Interface.Expression.IAssigment);
        }
    }
}
